home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / System / Directory source / savetext.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-28  |  1.9 KB  |  102 lines  |  [TEXT/KAHL]

  1. /*    SaveText.c
  2.  *
  3.  *    This writes out a text file containing the information that was contained in
  4.  *    the directory listing, albeit not in as nice a manner, maybe...
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include "struct.h"
  9.  
  10.  
  11.  
  12. /*    SaveText
  13.  *
  14.  *    Write the top window as text
  15.  */
  16.  
  17. SaveText()
  18. {
  19.     struct WindDraw *w;
  20.     Point p;
  21.     SFReply reply;
  22.     char buffer[255];
  23.     short refnum;
  24.     long len;
  25.     long x;
  26.     short y;
  27.     short llen;
  28.     struct DirectData *ptr;
  29.     long l;
  30.     CursHandle cursor;
  31.  
  32.     w = ((struct WindDraw *)FrontWindow());
  33.     if (w == NULL) return;
  34.     if (w->w.windowKind != WK_PLAN) return;
  35.  
  36.     p.h = p.v = 75;
  37.     strcpy(buffer,w->vName);
  38.     strcat(buffer,".DIR");
  39.     CtoPstr(buffer);
  40.     SFPutFile(p,"\pSave directory as:",buffer,NULL,&reply);
  41.     if (!reply.good) return;
  42.  
  43.     cursor = GetCursor(watchCursor);
  44.     HLock(cursor);
  45.     SetCursor(*cursor);
  46.     HUnlock(cursor);
  47.     HPurge(cursor);
  48.  
  49.     Create(reply.fName,reply.vRefNum,'EDIT','TEXT');
  50.     if (FSOpen(reply.fName,reply.vRefNum,&refnum)) return;
  51.     len = GetHandleSize(w->data) / sizeof(struct DirectData);
  52.     HLock(w->data);
  53.     ptr = *(w->data);
  54.     for (x = 0; x < len; x++) {
  55.         llen = 0;
  56.         for (y = 0; y < ptr[x].indent; y++) {
  57.             l = 2;
  58.             FSWrite(refnum,&l,"| ");
  59.             llen += 2;                        /* Tabs are 4 spaces */
  60.         }
  61.         llen++;
  62.         l = 1;
  63.         FSWrite(refnum,&l," ");
  64.         
  65.         PtoCstr(ptr[x].data);
  66.         l = strlen(ptr[x].data);
  67.         llen += l;
  68.         FSWrite(refnum,&l,ptr[x].data);
  69.         CtoPstr(ptr[x].data);
  70.         
  71.         if (ptr[x].auxdata[0] != '\0') {
  72.             while (llen < 60) {
  73.                 llen += 4 - llen % 4;
  74.                 l = 1;
  75.                 FSWrite(refnum,&l,"\t");
  76.             }
  77.             
  78.             PtoCstr(ptr[x].auxdata);
  79.             l = strlen(ptr[x].auxdata);
  80.             llen += l;
  81.             FSWrite(refnum,&l,ptr[x].auxdata);
  82.             CtoPstr(ptr[x].auxdata);
  83.             while (llen < 72) {
  84.                 llen += 4 - llen % 4;
  85.                 l = 1;
  86.                 FSWrite(refnum,&l,"\t");
  87.             }
  88.             
  89.             PtoCstr(ptr[x].auxdata2);
  90.             l = strlen(ptr[x].auxdata2);
  91.             llen += l;
  92.             FSWrite(refnum,&l,ptr[x].auxdata2);
  93.             CtoPstr(ptr[x].auxdata2);
  94.         }
  95.         l = 1;
  96.         FSWrite(refnum,&l,"\r");
  97.     }
  98.     HUnlock(w->data);
  99.     FSClose(refnum);
  100.     InitCursor();
  101. }
  102.